package com.hbnu.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect //此注解表明当前类的对象为切面

//增强类
public class CartLog {

    @Pointcut("execution(* com.hbnu.service.CartService.*(..))")
    public void pointcut(){

    }

    @Before("pointcut()")
    public void beforeAddCart(){
        System.out.println("前置通知：在商品添加到购物车之前执行的日志记录......");
    }


    @Around("pointcut()")
    public void aroundAddCart(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知：在将商品添加到购物车之前执行");

        proceedingJoinPoint.proceed(); //执行目标方法

        System.out.println("环绕通知：在将商品添加到购物车之后执行");
    }
}
